import { API_LIST } from '../../../Api/Api'
import { BuiltInData } from '../Common/common'
import { AddDataButton, DelDataButton, AnnexButton } from '../Common/options'

export const SecurityProblem = async ({ OptionsEvent, oneData, Permission }) => {
    const data = {
        hideInSearch: true,
        pageSize: 10,
        initialValues: { securityUuid: oneData.uuid },
        params: { pageIndex: 1, securityUuid: oneData.uuid },
        get: API_LIST()['getSecurityAttachment'],
        added: 'posSecurityAttachment',
        options: [
            oneData.auditStatus === -1 &&
                Permission.findIndex(v => v.uuid === '1956e28f-6152-45b9-81cc-8fc0868796da') !== -1 && (
                    <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增问题信息" />
                ),
        ],
        columns: [
            // 名称 描述 日期
            {
                dataIndex: 'securityUuid',
                title: 'securityUuid',
                valueType: 'hidden',
                hideInTable: true,
            },
            {
                dataIndex: 'originalName',
                title: '文件标题',
                valueType: 'input',
                hideInAdded: true,
                hideInModify: true,
            },
            {
                dataIndex: 'fileType',
                title: '文件类型',
                valueType: 'select',
                valueEnum: BuiltInData.FileType,
                hideInAdded: true,
                hideInModify: true,
                rules: true,
                width: 350,
            },
            {
                dataIndex: 'attachmentUuid',
                title: '问题附件',
                valueType: 'upload',
                valueFile: [1],
                fileUrl: 'fileUrl',
                rules: true,
                hideInTable: true,
            },
            {
                dataIndex: 'fileUrl',
                title: '文件附件',
                valueType: 'hidden',
                hideInSearch: true,
                hideInTable: true,
                hideInAdded: true,
                hideInModify: true,
                width: 400,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 300,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { uuid, fileUrl } = record
                    return [
                        fileUrl && <AnnexButton OptionsEvent={OptionsEvent} key="see" url={fileUrl} title="查看附件" />,
                        oneData.auditStatus === -1 &&
                            Permission.findIndex(v => v.uuid === 'a9973d99-d9c9-44d2-9345-e00fbc26a4d4') !== -1 && (
                                <DelDataButton
                                    OptionsEvent={OptionsEvent}
                                    key="del"
                                    title="删除"
                                    url="SecurityAttachment"
                                    uuid={[oneData.uuid, uuid]}
                                />
                            ),
                    ]
                },
            },
        ],
    }

    return data
}
